package com.hu.wc

import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

/**
 * @Author: hujianjun
 * @Create Date: 2020/11/6 18:08
 * @Describe:
 */
object WordCountStream {
  def main(args: Array[String]): Unit = {
    val streamEnv: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    val textDS: DataStream[String] = streamEnv.socketTextStream("localhost", 88)

    //此时如果不导入隐式转换包会报错
    textDS.flatMap(_.split(" "))
      .map((_, 1))
      .keyBy(0)
      .sum(1).print()

    streamEnv.execute("socket test")

  }
}
